package com.cacho.s2b.lesson.learn;


import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.util.HashMap;
import java.util.Map;

public class LearnJsonGson {
    public static void main(String[] args) {
        assembleGson();
    }

    public static void assembleGson(){
        Map<String, String> payload = new HashMap<>();
        payload.put("scope", "payments");
        payload.put("payload", "{\"sessionId\":\"test\"}");
        Gson gson = new Gson();
        String json = gson.toJson(payload);
        System.out.println("将Java对象转换为JSON字符串："+json);
        Map obj = gson.fromJson(json, Map.class);
        System.out.println("将json还原为Java对象："+obj);
    }
}
